package cn.rocksolid.sport.common.context;

public class RockSolidContextHolder {

  private static final InheritableThreadLocal<RockSolidContext> ITL_RS_CTX = new InheritableThreadLocal<>();

  private RockSolidContextHolder() {
  }

  public static RockSolidContext getContextSafe() {
    RockSolidContext ctx = ITL_RS_CTX.get();
    return null == ctx ? new RockSolidContextImpl() : ctx;
  }

  public static RockSolidContext getContext() {
    return ITL_RS_CTX.get();
  }

  public static void setContext(RockSolidContext context) {
    ITL_RS_CTX.set(context);
  }

  public static void removeContext() {
    ITL_RS_CTX.remove();
  }
}
